package com.baylor.xmpp.listener;

import org.jivesoftware.smack.Chat;
import org.jivesoftware.smack.ChatManagerListener;
import org.jivesoftware.smack.MessageListener;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.util.StringUtils;

import android.util.Log;

import com.xutils.XmppUtils;

public class TextChatManagerListener implements ChatManagerListener {

	@Override
	public void chatCreated(Chat chat, boolean arg1) {
		chat.addMessageListener(new MessageListener() {

			@Override
			public void processMessage(Chat arg0, Message msg) {
				// 登录用户
				StringUtils.parseName(XmppUtils.getInstance().getXmppConnection().getUser());
				// 发送消息用户
				msg.getFrom();
				// 消息内容
				String body = msg.getBody();
				
				Log.d("message", "msg=="+body);
				
//				boolean left = body.substring(0, 1).equals("{");
//				boolean right = body
//						.substring(body.length() - 1, body.length())
//						.equals("}");
//				if (left && right) {
//					try {
//						JSONObject obj = new JSONObject(body);
//						String type = obj.getString("messageType");
//						String chanId = obj.getString("chanId");
//						String chanName = obj.getString("chanName");
//					} catch (JSONException e) {
//						e.printStackTrace();
//					}
//
//				}
			}
		});
	}

}
